package com.lanou.dllo.vc.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.dllo.vc.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by dllo on 15/12/3.
 */
public class GroupDescAdapter extends BaseAdapter {
    private List<String> group_member;

    private Context context;
    private LayoutInflater inflater;

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {
                notifyDataSetChanged();
            }
        }
    };

    public GroupDescAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);

    }

    public void addData(List<String> group_member) {
        this.group_member = group_member;
        Log.d("GroupDescAdapter", "group_member.size():" + group_member.size());
        Message message = new Message();
        message.what = 0;
        handler.sendMessage(message);


    }

    @Override
    public int getCount() {
        return group_member != null && group_member.size() > 0 ? group_member.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return group_member.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_groupdesc, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String member = group_member.get(position);
        Log.i("lanou","-------pig------look---->>>"+member);
       // if (group_member.size()>= position ){
            if (member != null && member.length() > 0) {
                holder.group_members_name.setText(member);
                Log.d("GroupDescAdapter", member);
            }
     //   }
//        else if ( group_member.size()<getCount()-1){
//            holder.group_members_img.setImageResource(R.drawable.button_normal_shape);
//        }
//        else{
//            holder.group_members_img.setImageResource(R.drawable.address_selector);
//        }




//        if (position ==getCount()+1)
        return convertView;
    }

    class ViewHolder {
        @Bind(R.id.group_members_name)
        TextView group_members_name;
        @Bind(R.id.group_members_img)
        ImageView group_members_img;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
